package com.kk.demo.java8.lambda.base;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

/**
 * 入门，最简单的函数式编程1
 * @author liujun
 * @date 2016年8月27日
 * @verion 0.0.1
 */
public class LambdaUse01 {

    public static void main(String[] args) {
        Random rand = new Random();

        Integer[] value = new Integer[100];
        for (int j = 0; j < value.length; j++) {
            value[j] = rand.nextInt(10000);
        }

        System.out.println(Arrays.toString(value));

        System.out.println("最原始的java");
        Arrays.sort(value, new Comparator<Integer>() {
            @Override
            public int compare(Integer a, Integer b) {
                return Integer.compare(a, b);
            }
        });

        System.out.println(Arrays.toString(value));

        System.out.println("使用lambda表达式方法1");

        Arrays.sort(value, (Integer a, Integer b) -> {
            return Integer.compare(a, b);
        });
        System.out.println(Arrays.toString(value));

        System.out.println("使用lambda表达式方法1");

        Arrays.sort(value, (Integer a, Integer b) -> Integer.compare(a, b));
        System.out.println(Arrays.toString(value));

        System.out.println("使用lambda表达式方法3");
        Arrays.sort(value, (a, b) -> Integer.compare(a, b));

        System.out.println(Arrays.toString(value));

    }

}
